﻿Imports Control_Vuelos_BL
Imports Control_Vuelos_BE
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo

Public Class frmAdm_ManifiestoVuelo
    Private mCodViaje As String
    Private mCodReserva As String
    Private ReadOnly oProgramaViaje As New ProgramaViajeBL()
    Private pCodViaje As String
    Private ReadOnly oManifiesto As New ManifiestoBL()
    Private oCManifiesto As New C_ManifiestoBE()
    Private oDManifiesto As New D_ManifiestoBE()

    Private Sub frmAdm_ManifiestoVuelo_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        cbCodViaje.Properties.DataSource = oProgramaViaje.sp_Lista_ProgramaViaje(Nothing)
        cbCodViaje.Properties.View.BestFitColumns()
    End Sub

    Private Sub cbCodViaje_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles cbCodViaje.EditValueChanged
        Dim edit As DevExpress.XtraEditors.GridLookUpEdit = CType(sender, DevExpress.XtraEditors.GridLookUpEdit)
        Dim row As DataRow = edit.Properties.View.GetDataRow(edit.Properties.View.FocusedRowHandle)
        If Not row Is Nothing Then
            gDesLugarOrigen.EditValue = row("DesLugarOrigen")
            gDesLugarDestino.EditValue = row("DesLugarDestino")
            gNroCupos.EditValue = row("NroCupos")
            gFchViaje.EditValue = row("FchViaje")
            gNomEmpresa.EditValue = row("NomEmpresa")
            pCodViaje = row("CodViaje")
        End If
    End Sub

    Public Property CodViaje() As String
        Get
            Return mCodViaje
        End Get
        Set(value As String)
            mCodViaje = value
        End Set
    End Property

    Public Property CodReserva() As String
        Get
            Return mCodReserva
        End Get
        Set(value As String)
            mCodReserva = value
        End Set
    End Property

    Private Sub cmdacpbtn_Click(sender As System.Object, e As System.EventArgs) Handles cmdacpbtn.Click
        If CodViaje = pCodViaje Then
            MessageBox.Show(" No puedes mover al pasajero a su mismo vuelo ", "Manifiesto", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        End If
        oCManifiesto = oManifiesto.pr_RecuperarCabecera(CodViaje)
        If oCManifiesto.EstadoManifiesto <> "0" Then
            MessageBox.Show(" No puedes mover al pasajero porque el Manifiesto esta Cerrado ", "Manifiesto", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        End If
        oDManifiesto = oManifiesto.pr_RecuperarDetalle(CodViaje, CodReserva)
        If oDManifiesto.FlgLock = 1 Then
            MessageBox.Show(" El Pasajero esta bloqueado por estar confirmado ", "Manifiesto", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        End If
        If oManifiesto.pr_UpdateDetalleManifiestoViaje(CodViaje, CodReserva, pCodViaje) Then
            Close()
        End If
    End Sub

    Private Sub cbCodViaje_Popup(sender As Object, e As System.EventArgs) Handles cbCodViaje.Popup
        Dim popup As DevExpress.Utils.Win.IPopupControl = CType(sender, DevExpress.Utils.Win.IPopupControl)
        Dim popupForm As DevExpress.XtraEditors.Popup.PopupGridLookUpEditForm = CType(popup.PopupWindow, DevExpress.XtraEditors.Popup.PopupGridLookUpEditForm)
        popupForm.Width = CType(sender, Control).Width
    End Sub

End Class